home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / emacs16d.zip / _UTILS.MIN < prev    next >
Text File  |  1991-07-19  |  12KB  |  509 lines

  1.  
  2.  
  3.  
  4. Name:Fall-but-last
  5. Return all but the last argument concatenated together.
  6. [*]#(==,arg2,,,(
  7.     arg1
  8.     #(SELF,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
  9. ))[*]
  10.  
  11.  
  12. Name:Fand
  13. If arg1 returns yes and arg2 returns yes, return arg3 else arg4.
  14. [*]#(==,#(arg1,(#(arg2,yes,no)),no),yes,(arg3),(arg4))[*]
  15.  
  16.  
  17. Name:Fbreak-first
  18. [*]
  19. #(==,##(arg1),,,(
  20.     #(ds,bf-t,#(fm,arg1,(arg2)))
  21.     #(ds,arg1,##(arg1))
  22.     #(==,##(bf-t),,(#(SELF,(arg1),(arg2))),(##(bf-t)#(es,bf-t)))
  23. ))
  24. [*]
  25.  
  26.  
  27. Name:Fbreak-last
  28. [*][*]
  29.  
  30.  
  31. Name:Fbreak-last-do
  32. [*][*]
  33.  
  34.  
  35. Name:Fexecute-and-mark
  36. Evaluates arg1 and creates a mark around anything it may have put in the text
  37. buffer.
  38. [*]
  39. #(pm,2)
  40. #(is,!)
  41. #(sm,0,<)
  42. arg1
  43. #(sp,0)
  44. #(dm,>)
  45. #(Fset-new-mark,.)
  46. #(sp,1)
  47. #(pm)
  48. [*]
  49.  
  50.  
  51. Name:Ffind-a-string
  52. Find all the strings that match arg1.
  53. [*]#(Ffind-a-match,
  54.     #(Flist-all-strings,arg1)
  55.     #(Fmultiple,(Fprefix-matches,arg1,2),##(ls,(,),F!),SELF)
  56. ,(arg2),(arg3),(arg4),1)[*]
  57.  
  58.  
  59. Name:Ffirst
  60. Given a list of arguments, return only the first.
  61. [*]arg1[*]
  62.  
  63.  
  64. Name:Fflush-input-buffer
  65. Ring the bell and wait one second for the user to stop typing.  Used to prevent
  66. the user from typing ahead when he has already made a mistake.  The first time
  67. give them 250 ms to react.
  68. [*]#(bl)
  69. #(==,##(it,100),Timeout,(
  70.     #(bl)
  71. ),(
  72.     #(SELF)
  73. ))[*]
  74.  
  75.  
  76. Name:Ffourth
  77. Return the fourth argument.
  78. [*]arg4[*]
  79.  
  80.  
  81. Name:Fhead
  82. Return the string that is the head of the ring specified by arg1.
  83. [*]##(gn,##(arg1.head),10000)
  84. #(rs,##(arg1.head))[*]
  85.  
  86.  
  87. Name:Fisupper
  88. #(Fisupper,CHAR,YES,NO) tests the ASCII value of char and executes YES
  89. if the character is an upper case letter or NO if not.
  90. [*]#(g?,65,arg1,(arg3),(
  91.     #(g?,arg1,90,(arg3),(arg2))
  92. ))[*]
  93.  
  94.  
  95. Name:Fleave
  96. Used by redefine and unredefine to position the string pointer.
  97. [*]
  98. #(ds,arg1,(arg3))
  99. #(..,##(gn,arg1,##(--,##(nc,##(gs,arg1)),arg2)))
  100. [*]
  101.  
  102.  
  103. Name:Flist-all-strings
  104. List all strings beginning with arg1 in all libraries.
  105. [*]#(Ffor-all-libs,(SELF-do,arg1),SELF)[*]
  106.  
  107.  
  108. Name:Flongest-prefix
  109. Find the longest common prefix in the comma-terminated list of strings given in
  110. arg1.  Ignore arg2 characters at the beginning of each string.  Define the
  111. string "longest-matched" if one of the strings is equal to the prefix.
  112. Tests:
  113. #(Flongest-prefix,(abc,abc,))##(temp) should be abc#(n?,longest-matched, and longest matched)
  114. #(Flongest-prefix,(abc,abd,))##(temp) should be ab#(n?,longest-matched, and longest matched)
  115. #(Flongest-prefix,(abc,ab,))##(temp) should be ab#(n?,longest-matched, and longest matched)
  116. End of tests.
  117. [*]#(ds,temp,#(Ffirst,arg1))
  118. #(es,longest-matched,temp1)
  119. #(Fmultiple,(SELF-do,arg2),(arg1),SELF)[*]
  120.  
  121.  
  122. Name:Flongest-prefix-do
  123. Find the longest common prefix in arg2 and ##(temp).  Ignore arg1 characters
  124. at the beginning of each string.
  125. Tests:
  126. #(es,longest-matched)#(ds,temp,abcd)#(Flongest-prefix-do,,abc)##(gs,temp) should be abc#(n?,longest-matched, and longest matched)
  127. #(es,longest-matched)#(ds,temp,abc)#(Flongest-prefix-do,,abcd)##(gs,temp) should be abc#(n?,longest-matched, and longest matched)
  128. #(es,longest-matched)#(ds,temp,abc)#(Flongest-prefix-do,,abc)##(gs,temp) should be abc#(n?,longest-matched, and longest matched)
  129. End of tests.
  130. [*]#(ds,temp1,arg2)
  131. #(..,##(gn,temp1,arg1,!!!))
  132. #(ds,temp,##(gn,temp,arg1)#(SELF-do))
  133. #(==,##(go,temp1,!!!),!!!,(
  134.     #(rs,temp1)
  135.     #(..,##(gn,temp,arg1,!!!))
  136.     #(ds,temp,##(gn,temp1,arg1)#(temp))
  137. ))[*]
  138.  
  139.  
  140. Name:Flongest-prefix-do-do
  141. Compare the prefix and the new candidate, character by character.  If this one
  142. matches exactly, define longest-matched.  If this one made the prefix shorter,
  143. undefine longest-matched.
  144. Tests:
  145. #(es,longest-matched)#(ds,temp,)#(ds,temp1,)#(Flongest-prefix-do-do,a,b) should be #(n?,longest-matched, and longest matched)
  146. #(es,longest-matched)#(ds,temp,)#(ds,temp1,)#(Flongest-prefix-do-do,b,a) should be #(n?,longest-matched, and longest matched)
  147. #(es,longest-matched)#(ds,temp,)#(ds,temp1,)#(Flongest-prefix-do-do,a,a) should be a#(n?,longest-matched, and longest matched)
  148. #(es,longest-matched)#(ds,temp,b)#(ds,temp1,b)#(Flongest-prefix-do-do,a,a) should be ab#(n?,longest-matched, and longest matched)
  149. #(es,longest-matched)#(ds,temp,a)#(ds,temp1,b)#(Flongest-prefix-do-do,a,a) should be a#(n?,longest-matched, and longest matched)
  150. #(es,longest-matched)#(ds,temp,a)#(ds,temp1,)#(Flongest-prefix-do-do,a,a) should be a#(n?,longest-matched, and longest matched)
  151. #(es,longest-matched)#(ds,temp,)#(ds,temp1,a)#(Flongest-prefix-do-do,a,a) should be a#(n?,longest-matched, and longest matched)
  152. [*]#(==,(arg1),(arg2),(
  153.     #(==,(arg1),!!!,(
  154.         #(ds,longest-matched)
  155.     ),(
  156.         (arg1)
  157.         #(SELF,##(go,temp,!!!),##(go,temp1,!!!))
  158.     ))
  159. ),(
  160.     #(==,(arg2),!!!,(
  161.         #(ds,longest-matched)
  162.     ),(
  163.         #(==,(arg1),!!!,,(
  164.             #(es,longest-matched)
  165.         ))
  166.     ))
  167. ))[*]
  168.  
  169.  
  170. Name:Flooking-at
  171. Args:(regexp,if-yes,if-no)
  172. [wjm 4/7/90]
  173.     Return <if-yes> if the string after point matches <regexp>, else 
  174. return <if-no>.  Mark 0 is the initial point, and mark 2 is the end of the
  175. match.
  176. [*]
  177. #(pm,3)
  178. #(sp,$>)
  179. #(sm,1)
  180. #(sp,0)
  181. #(lp,(regexp),,y)
  182. #(==,#(l?,.,1,1,2,(#(==,#(rc,1),0,y))),y,(if-yes),(if-no))
  183. #(pm)
  184. [*]
  185.  
  186.  
  187. Name:Flookup
  188. Search through the string named in arg1 for arg2 (callers
  189. responsibility to ensure that the match is complete), and execute
  190. everything up to the next arg3.  If there is no arg2 in the list,
  191. execute arg4.
  192. [*]#(..,##(fm,arg1,(arg2),(
  193.     #(gn,arg1,1000)
  194. )))
  195. #(fm,arg1,(arg3),(arg4))
  196. #(rs,arg1)
  197. [*]
  198.  
  199.  
  200. Name:Floop
  201. Return arg2 copies of arg1, active
  202. [*]#(g?,arg2,0,(arg1#(SELF,(arg1),#(--,arg2,1))))[*]
  203.  
  204.  
  205. Name:Fmax
  206. #(Fmax,A,B) returns the numerically greater of A and B.
  207. [*]#(g?,arg1,arg2,arg1,arg2)[*]
  208.  
  209.  
  210. Name:Fmodulus
  211. #(Fmodulus,ARG) Returns ARG if ARG is positive,
  212. else -ARG if ARG is negative (special cases: 1 for void and `-').
  213. [*]#(==,(arg1),,1,(
  214.     #(==,(arg1),-,1,(
  215.         #(g?,0,(arg1),(#(--,0,(arg1))),(arg1))
  216.     ))
  217. ))[*]
  218.  
  219.  
  220. Name:Fmore
  221. Given a list of items, show them on the screen, one per line, pausing every
  222. #(lv,b) lines to let the user press a key.  If they quit in the middle, force
  223. a redisplay because that's what #(Fhit-any-key) does
  224. [*]#(ds,line,1)
  225. #(==,#(Fmultiple,SELF-do,##(temp,(,)),SELF),q,(
  226.     #(rd)
  227. ),(
  228.     #(Fhit-any-key)
  229. ))[*]
  230.  
  231.  
  232. Name:Fmore-do
  233. [*]#(ds,line,##(++,##(line),1))
  234. #(g?,##(line),##(lv,bl),(
  235.     #(ow,([More?][More?]))
  236.     #(Fcase,#(g),
  237.         (C-m,(#(ds,line,##(lv,bl)))),
  238.         (Return,(#(ds,line,##(lv,bl)))),
  239.         (q,(q#(ds,list.Fmore,(,)))),
  240.         (#(ds,line,2))
  241.     )
  242.     #(ow,())
  243. ))
  244. #(ow,arg1(
  245. ))[*]
  246.  
  247.  
  248. Name:Fmultiple
  249. #(Fmultiple,STRING,LIST,LISTNAME) will execute #(STRING,LIST ELEMENT) where LIST
  250. consists of LIST ELEMENTS seperated by commas.  Note that LIST can not be
  251. scanned, otherwise the commas will be converted to argument seperators.  Use
  252. parentheses to protect LIST, or use a neutral function to return its results
  253. unscanned.
  254.     Fmultiple can be used recursively if you specify different
  255. LISTNAMES for each list.  #(Fmultiple,foo,bar,SELF) works nicely.
  256.  
  257. [*]#(ds,list.arg3,(arg2))
  258. #(SELF-do,(arg1),##(fm,list.arg3,(,),!!!),arg3)
  259. [*]
  260.  
  261.  
  262. Name:Fmultiple-do
  263. [*]#(==,arg2,!!!,(#(es,list.arg3)),(
  264.     #(==,arg2,,,(#(arg1,arg2)))
  265.     #(Fbreak,,(
  266.     #(SELF,(arg1),##(fm,list.arg3,(,),!!!),arg3)))))[*]
  267.  
  268.  
  269. Name:Fmv
  270. Rename a function definition to another name.
  271. [*]#(n?,arg1,(
  272.     #(ds,arg2,##(gs,arg1,#(Farglist)))
  273.     #(mp,arg2,#(Farglist))
  274.     #(es,arg1)
  275. ))[*]
  276.  
  277.  
  278. Name:Fonly-last
  279. [*]#(==,arg2arg3arg4arg5arg6arg7arg8arg9,,(
  280.     arg1
  281. ),(
  282.     #(SELF,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
  283. ))[*]
  284.  
  285.  
  286. Name:For
  287. If arg1 returns yes or arg2 returns yes, return arg3 else arg4.
  288. [*]#(==,#(arg1,yes,(#(arg2,yes,no))),yes,(arg3),(arg4))[*]
  289.  
  290.  
  291. Name:Fpad-to-column
  292. #(Fpad-to-column,COL) will insert enough spaces into the line to
  293. put the point at the given column.
  294. [*]#(For,(==,##(F-indent-tabs-mode),),(g?,##(lv,cs),(arg1)),(
  295.     #(==,##(rm,<),(    ),(#(dm,<)))
  296.     #(is,#(Floop, ,##(--,(arg1),##(lv,cs))))
  297. ),(
  298.     #(is,(    ))
  299.     #(SELF,(arg1))
  300. ))[*]
  301.  
  302.  
  303. Name:Fpad-with
  304. Pad a string arg2 with arg1 on the left and arg3 on the right until it is
  305. arg4 long.
  306. [*]#(g?,arg4,##(nc,arg2),(
  307.     #(SELF,(arg1),(arg1arg2arg3),(arg3),(arg4))
  308. ),(
  309.     arg2
  310. ))[*]
  311.  
  312.  
  313. Name:Fparens
  314. Surround arg1 with parens.
  315. [*](arg1)[*]
  316.  
  317.  
  318. Name:Fprefix-matches
  319. If arg1 matches arg3 starting at the third character, and the string whose
  320. name starts at the second character doesn't exist, return arg3 starting
  321. at the arg2th character.
  322. [*]#(ds,temp,arg3)
  323. #(..,##(gn,temp,3))
  324. #(==,##(fm,temp,arg1,no good),,(
  325.     #(rs,temp)
  326.     #(..,##(gn,temp,2))
  327.     #(n?,##(gs,temp),,(
  328.         #(rs,temp)
  329.         #(..,##(gn,temp,arg2))
  330.         ##(temp)(,)
  331.     ))
  332. ))
  333. [*]
  334.  
  335.  
  336. Name:Fr
  337. Make arg1 into a string, and substitute parameters arg2 for ARG1, arg3 for ARG2,
  338. etc...  Obviously this is a kludge that will only work to one level, but it's
  339. very handy.
  340. [*]#(ds,temp,(arg1))
  341. #(mp,temp,,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8,ARG9)
  342. #(temp,(arg2),(arg3),(arg4),(arg5),(arg6),(arg7),(arg8),(arg9))
  343. [*]
  344.  
  345.  
  346. Name:Fredefine
  347. Redefine the string arg1 so that it appears to contain only arg2.
  348. [*]
  349. #(Fleave,arg1,##(nc,(arg2)),
  350.     ##(nc,##(arg1))
  351.     /^/
  352.     #(rs,arg1)
  353.     ##(gs,arg1)
  354.     (arg2)
  355. )
  356. [*]
  357.  
  358.  
  359. Name:Fregexp-quote
  360. Quote an ordinary string so that any metacharacters will be interpreted as
  361. ordinary characters.
  362. #(Fregexp-quote,^$.*[]\)
  363. [*]#(ds,temp,arg1)
  364. #(mp,temp,,^,$,.,*,+,[,],\)
  365. ##(temp,\^,\$,\.,\*,\+,\[,\],\\)[*]
  366.  
  367.  
  368. Name:Freplace-head
  369. [*]#(ds,##(arg1.head),##(gn,value,10000)#(rs,value))[*]
  370.  
  371.  
  372. Name:Fresolve-name
  373. Given a string name in arg1, make sure that it is non-ambiguous and execute arg2
  374. if it is.  If arg3 is non-null, use it as the prefix character.
  375. [*]#(Ffind-a-string,#(==,arg3,,:,arg3)arg1,(
  376.     #(bl)
  377.     #(an,"arg1" not found)
  378. ),(
  379.     arg2
  380. ),(
  381.     #(n?,##(temp),(
  382.         arg2
  383.     ),(
  384.         #(bl)
  385.         #(an,"arg1" is ambiguous)
  386.     ))
  387. ))
  388. [*]
  389.  
  390.  
  391. Name:Fright
  392. Return the rightmost arg2 characters of arg1.
  393. [*]#(ds,SELF temp,(arg1))
  394. #(..,##(gn,SELF temp,##(--,##(nc,(arg1)),arg2)))
  395. ##(SELF temp)
  396. #(es,SELF temp)
  397. [*]
  398.  
  399.  
  400. Name:Fring
  401. [*]#(ds,arg1.size,arg2)
  402. #(ds,arg1.head,arg1.0)[*]
  403.  
  404.  
  405. Name:Frotate
  406. [*]#(ds,arg1.head,#(%%,##(++,##(arg1.head),1),##(arg1.size)))[*]
  407.  
  408.  
  409. Name:Frun-some-functions
  410. Run functions given in the args until one of them fails to return "again".
  411. [*]#(==,#(arg1),again,(
  412.     #(SELF,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
  413. ))
  414. [*]
  415.  
  416.  
  417. Name:Fsecond
  418. Return the second argument.
  419. [*]arg2[*]
  420.  
  421.  
  422. Name:Fsignum
  423. #(Fsignum,ARG,PLUS,MINUS) Returns PLUS if ARG is positive or void,
  424. else MINUS if ARG is negative or `-'.
  425. [*]#(==,(arg1),,(arg2),(
  426.     #(==,(arg1),-,(arg3),(
  427.         #(g?,0,(arg1),(arg3),(arg2))
  428.     ))
  429. ))[*]
  430.  
  431.  
  432. Name:Fskip-chars-forward
  433. Args:(class,end)
  434. Skips past all characters in the given character class.  If end is non-null,
  435. then it is the mark to stop searching.  Otherwise the search stops at the
  436. end of the buffer.
  437. [*]#(pm,1)
  438. #(lp,[class]*,,R)
  439. #(l?,.,##(==,end,,],end),,0,(
  440.     #(sp,0)
  441. ))
  442. #(pm)[*]
  443.  
  444.  
  445. Name:Ftail
  446. Return the rest of the arguments.
  447. [*]arg2(,)arg3(,)arg4(,)arg5(,)arg6(,)arg7(,)arg8(,)arg9[*]
  448.  
  449.  
  450. Name:Fthird
  451. Return the third argument.
  452. [*]arg3[*]
  453.  
  454.  
  455. Name:Funredefine
  456. Undo the effects of the previous redefine.
  457. [*]
  458. #(ds,temp,##(nc,##(arg1)))
  459. #(rs,arg1)
  460. #(Fleave,arg1,##(fm,arg1,/^/),##(gn,arg1,
  461.     #(--,##(nc,##(arg1)),##(temp))
  462. ))
  463. #(==,##(arg1),,(#(es,arg1)))[*]
  464.  
  465.  
  466. Name:Funrotate
  467. Back up a ring.
  468. [*]#(ds,arg1.head,#(%%,
  469.     ##(++,
  470.         ##(++,##(arg1.head),-1),
  471.         ##(arg1.size)),
  472.     ##(arg1.size)))[*]
  473.  
  474.  
  475. Name:Fwhile-yes
  476. Repeatedly execute arg1 so long as it returns 'yes'.
  477. [*]#(==,arg1,yes,(#(SELF,(arg1))))[*]
  478.  
  479.  
  480. Name:Fwhitespace
  481. Return arg1 if the character to the right is space, tab, or newline else arg2.
  482. If arg3 is non-null, don't match newline.
  483. [*]#(==,##(rm,>), ,(arg1),(
  484.     #(==,##(rm,>),(    ),(arg1),(
  485.         #(==,##(rm,>),(arg3
  486. ),(arg1),(
  487.             #(==,##(rm,>),,(arg1),(arg2))
  488.         ))
  489.     ))
  490. ))[*]
  491.  
  492.  
  493. Name:Fyes-or-no
  494. #(Fyes-or-no,PROMPT,YES,NO) will read a line and execute YES if
  495. that line is 'yes'.  It will execute NO if the line is 'no'.
  496. It keeps trying until a recognized word is entered.
  497. [*]#(ds,value)
  498. #(Freadline,(arg1 ((yes/no)) ),(
  499.     #(Fcase,##(value),
  500.         (yes,(arg2)),
  501.         (no,(arg3)),
  502.         (
  503.             #(an,Please enter 'yes' or 'no'.)
  504.             #(ds,temp,##(it,200))
  505.             #(==,##(temp),Timeout,,(#(Fkbd-in,##(temp))))
  506.             #(SELF,(arg1),(arg2),(arg3))
  507.         )
  508.     )
  509. ))[*]